package dao;

import java.io.InputStream;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import main.App;
import role.Memo;
import role.Tag;

public class Dao {

	String resource = "generatorConfig.xml";
	InputStream is = App.class.getClassLoader().getResourceAsStream(resource);
	SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
	SqlSession session = sessionFactory.openSession();

	public void insertMemo(Memo memo) {
		MemoMapper memomapper = session.getMapper(MemoMapper.class);
		memomapper.insert(memo);
		session.commit();

	}

	public void insertTag(Tag tag) {
		TagMapper tagmapper = session.getMapper(TagMapper.class);
		tagmapper.insert(tag);
		session.commit();

	}

	public int selectIdOfTag(String name) {
		TagMapper tagmapper = session.getMapper(TagMapper.class);
		int tagId = tagmapper.selectIdByName(name);
		session.commit();
		return tagId;
	}

	public void sessionClose() {
		session.close();
	}

}
